package thread4.TEST;

public class test1 {
    public static void main(String[] args) {
        int a = 10;
        Object object1 = new Object();
        Object object2 = new Object();//object是锁作为锁了

        Thread thread1 = new Thread(() -> {
            synchronized (object2) {
                int b = a + 10;
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                try {
                    object2.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

        });
        Thread thread2 = new Thread(() -> {
            //object2.notify();
            System.out.println("thread2执行到");
            try {
                thread1.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("thread2阻塞之后");
            //wait(1000);
        });
        Thread thread3 = new Thread(() -> {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //object2.notify();
            synchronized (object2) {//拿到锁后才能对锁操作
                object2.notify();//调用这个方法了，视为锁了，虽然是成员/局部变量
            }
        });

        thread1.start();
        thread2.start();
        thread3.start();

    }
}
